﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MyGUI.wcfFlightService;
using Model_Layer;

namespace MyGUI
{
    public partial class Checkout : Form
    {
        private wcfFlightService.IService wcfService;
        TextBox[] passengerBoxes;

        public Checkout(int numPassenger)
        {
            InitializeComponent();
            wcfService = new wcfFlightService.ServiceClient();
            //createPassengerBoxes(1);
            //test();
            createPassengerBoxes(numPassenger);
        }

        public void test()
        {
            TextBox passenger = new TextBox();
            passenger.Location = new System.Drawing.Point(244, 30);
            passenger.Name = "passengerBox";
            passenger.Size = new System.Drawing.Size(100, 20);
            passenger.TabIndex = 13;
            this.Controls.Add(passenger);
        }

        //public void createPassengerBoxes(int passengerNumber)
        //{
        //    int i = 0;
        //    int columnYaxisSet = 19;
        //    int pasBoxNumber = 0;
        //    string boxName = "passenger" + pasBoxNumber;
        //    int tabIndex = 13;
        //    while (i < passengerNumber)
        //    {
        //        TextBox passenger = new TextBox();
        //        passenger.
        //        passenger.Location = new System.Drawing.Point(15, columnYaxisSet);
        //        passenger.Name = "passengerBox" + i;
        //        passenger.Size = new System.Drawing.Size(100, 20);
        //        passenger.TabIndex = 11;
        //        this.Controls.Add(passenger);

        //        columnYaxisSet = columnYaxisSet + 20;
        //        tabIndex = tabIndex + 1;
        //        pasBoxNumber = pasBoxNumber + 1;

        //    }
        //}

        public void test2()
        {

        }

        public void createPassengerBoxes(int numPassenger)
        {
            passengerBoxes = new TextBox[numPassenger];

            for (int u = 0; u < passengerBoxes.Count(); u++)
            {
                passengerBoxes[u] = new TextBox();
            }
            int i = 0;
            foreach (TextBox txt in passengerBoxes)
            {
                string name = "passenger" + i.ToString();

                txt.Name = name;
                txt.Text = name;
                txt.Location = new Point(244, 32 + (i * 28));
                txt.Size = new System.Drawing.Size(200, 20);
                txt.Visible = true;
                this.Controls.Add(txt);
                i++;
            }
        }

        private List<String> GetTextBoxStrings()
        {
            List<String> list = new List<String>();
            foreach (Control c in this.Controls)
            {
                if (c is TextBox)
                {
                    list.Add(((TextBox)c).Text);
                }
            }
            return list;
        }

        private void buyTravelButton_Click(object sender, EventArgs e)
        {
            List<String> passengerPassports = GetTextBoxStrings();
            List<Passenger> passengerList = new List<Passenger>();
            Customer customerObj = new Customer();
            customerObj.Fname = nameBox.Text;
            customerObj.Lname = lNameBox.Text;
            customerObj.Gender = genderComboBox.Text;
            customerObj.Paddress = addressBox.Text;
            customerObj.Email = emailBox.Text;
            customerObj.IsCusFlag = true;
            customerObj.IsPassFlag = true;
            
            foreach (string c in passengerPassports)
            {
                Passenger passengerObj = new Passenger();
                passengerObj.PassportNo = c;
                passengerObj.IsCusFlag = false;
                passengerObj.IsPassFlag = true;
                passengerList.Add(passengerObj);
            }
        }
    }
}
